package com.lq.educationsystem.examination.controller;


import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultBuild;
import com.lq.educationsystem.common.util.ResultPage;
import com.lq.educationsystem.common.vo.StudentExaminationPageVo;
import com.lq.educationsystem.examination.entiy.ExaminationTb;
import com.lq.educationsystem.examination.entiy.StudentExaminationTb;
import com.lq.educationsystem.examination.service.ExaminationStudentBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Tag(name = "学生考试信息")
@RequestMapping("/examination/student/base")
@RestController
public class ExaminationStudentBaseController {

    //注入service
    @Autowired
    ExaminationStudentBaseService examinationStudentBaseService;

    //增加

    @Operation(summary = "插入学生考试信息")
    @PostMapping("/insert")
    public Result insertInfo(@RequestBody StudentExaminationTb studentExaminationInfo){
        //插入数据
        examinationStudentBaseService.insertInfo(studentExaminationInfo);
        return ResultBuild.buildOk();




    }
    //删除
    @Operation(summary = "通过学生id删除学生考试信息")
    @PostMapping("/delete")
    public Result deleteById(@RequestBody StudentExaminationTb studentExaminationInfo){
        //通过表信息id
        Integer studentExaminationId = studentExaminationInfo.getStudentExaminationId();
        examinationStudentBaseService.deleteById(studentExaminationId);

        //删除
        return ResultBuild.buildOk();

    }
    //更新
    @Operation(summary = "更新学生考试信息")
    @PostMapping("/update")
    public Result updateInfo(@RequestBody StudentExaminationTb studentExaminationInfo){
        examinationStudentBaseService.updateInfo(studentExaminationInfo);
        return ResultBuild.buildOk();
    }
    //通过id查询
    @Operation(summary = "查询考试信息通过考试id")
    @PostMapping("/querybyid")
    public Result<StudentExaminationTb> queryById(@RequestBody StudentExaminationTb studentExaminationInfo){
        Integer studentExaminationId = studentExaminationInfo.getStudentExaminationId();
        //通过id查询
        Result result= examinationStudentBaseService.queryById(studentExaminationId);


        return result;
    }

    //查询
    @Operation(summary = "分页查询学生考试信息")
    @PostMapping("/query")
    public ResultPage<StudentExaminationTb> queryList(@RequestBody StudentExaminationPageVo studentExaminationPageVo){
        ResultPage<StudentExaminationTb> studentExaminationPageVoResultPage =examinationStudentBaseService.queryList(studentExaminationPageVo);


        return studentExaminationPageVoResultPage;
    }

    /**
     * 根据学生id和考试id批量查询数据
     */
    @Operation(summary = "根据学生id和考试id批量查询数据")
    @PostMapping("/query/batch/student")
    public ResultPage<StudentExaminationTb> queryStudentExaminationInfoByStudentIdAndExaminationId(@RequestBody List<Integer> examinationIdList, @RequestParam("studentId") Integer studentId) {
        ResultPage<StudentExaminationTb> studentExaminationTbResultPage = examinationStudentBaseService.queryStudentExaminationInfoByStudentIdAndExaminationId(examinationIdList,studentId);
        return studentExaminationTbResultPage;
    }
    /**
     * 根据考试id和学生id集合批量添加信息
     */

    @Operation(summary = "根据考试id和学生id集合批量添加信息")
    @PostMapping("/add/batch/examination")
    public Result addBatchStudentExaminationInfoByExaminationIdAndStudentId(@RequestBody List<Integer> studentIdInfoList ,@RequestParam("examinationId") Integer examinationId){
        //考试信息发布
        Result result= examinationStudentBaseService.addBatchStudentExaminationInfoByExaminationIdAndStudentId(studentIdInfoList,examinationId);
        return result;
    }
}
